package org.shiro.matcher;

import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.credential.CredentialsMatcher;
import org.shiro.util.JwtUtil;

/**
 * @author 党怡承
 * @version 1.0
 * @date 2021-04-24 16:14
 */
public class JwtCredentialsMatcher implements CredentialsMatcher {
    @Override
    public boolean doCredentialsMatch(AuthenticationToken authenticationToken, AuthenticationInfo authenticationInfo) {
        String authToken = (String) authenticationToken.getCredentials();
        String username = JwtUtil.getUsername(authToken);
        try{
            JwtUtil.verify(authToken,username);
            return true;
        }catch (Exception e){
            e.printStackTrace();
        }
        return false;
    }
}
